<template>
	<view>
			<view class="uni-card" v-for="(item, index) in records">
				<view class="uni-card-content">
					<view class="uni-card-content-inner" v-if="typeId == 0">
						您购买了{{item.orderName}}
					</view>
					<view class="uni-card-content-inner" v-if="typeId == 1">
						您充值了购买了{{item.orderName}}
					</view>
					<view class="uni-card-content-inner" v-if="typeId == 2">
						您购买了{{item.msgCount}}条小纸条
					</view>
				</view>
				<view class="uni-card-footer">{{item.createdStamp}}</view>
			</view>

	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import {getOrders} from '@/api/buy/order';

	import {getMessageCount} from '@/api/ucenter/index';

	export default {
		data() {
			return {
				titles: [
					"VIP购买记录",
					"充值记录",
					"小纸条购买记录"
				],
				orderTypes: [
					"SERVICE_ORDER_VIP",
					"SERVICE_ORDER_WEALTH"
				],
				typeId: 0,
				page: 1,
				pageSize: 20,
				records: []
			};
		},
		computed:{
		...mapGetters(
			["userId"]
		)},
		onLoad(e) {
			
			uni.setNavigationBarTitle({
				title: this.titles[e.typeId] 
			})
			
			if(e.typeId <3) {
				this.getOrderRecords(this.orderTypes[e.typeId])
			} else {
				this.getMessageCount();
			}
		},
		methods: {
			getOrderRecords(orderTypeId) {
				getOrders(this.getParameters(orderTypeId)).then(response => {
					if(response.status == 200 && response.data.length > 0) {
						this.baseUrl = getUrl();
						this.records = this.records.concat(response.data) 
						this.page++;
					}
				});
			},
			getParameters(orderTypeId) {
				let params =  {page: this.page,
					limit: this.pageSize,
					partyId: this.userId,
					orderBy: "createdStamp",
					sort: "desc"};
				if(orderTypeId != undefined)
					params.orderTypeId = orderTypeId;
				return params;
			},
			getMessageCount() {
				getMessageCount(getParameters()).then(response => {
					if(response.status == 200 && response.data.length > 0) {
						
					}
				});
			}
		}
	}
</script>

<style>

</style>
